package
{
	import com.terrynoya.common.control.MButton;
	import com.terrynoya.display.MRect;
	import com.terrynoya.qtree.QTree;
	import com.terrynoya.qtree.QTreeNode;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class QTreeTEST extends Sprite
	{
		private static const RECT_WIDTH:Number = 500;
		
		private var tree:QTree = new QTree();
		
		
		public function QTreeTEST()
		{
			this.stage.scaleMode = StageScaleMode.NO_SCALE;
			this.stage.align = StageAlign.TOP_LEFT;
			var w:Number = RECT_WIDTH;
			tree.generate(new Point(0,0),new Point(w,0),new Point(w,w),new Point(0,w));
			for(var i:int =0;i<100;i++)
			{
				this.addNode(this.getRadomPos());
			}
//			this.addNode(new Point(0,0));
//			this.addNode(new Point(26,5));
//			this.addNode(new Point(8,5));
			tree.draw(this);
			tree.detect(); 
		} 
		
		private function addNode(p:Point):void
		{
			var rect:MRect = new MRect(10);
			rect.x = p.x;
			rect.y = p.y;
//			trace(p.toString());
			this.addChild(rect);
			tree.locate(rect); 
		}
		
		private function getRadomPos():Point
		{
			return new Point(ran,ran);
		}
		
		private function get ran():int
		{
			return Math.ceil(Math.random()*(RECT_WIDTH - 10));
		}
		
		private function addRect(pos:Point):MRect
		{
			var rect:MRect = new MRect(10);
			rect.x = pos.x;
			rect.y = pos.y;
			this.addChild(rect);
			return rect;
		} 
	}
}